<template>
    <a-carousel autoplay :arrows="props.arrows" :style="props.bodyStyle">
        <template #prevArrow>
            <div class="custom-slick-arrow" style="left: 10px; z-index: 1">
                <left-circle-outlined />
            </div>
        </template>
        <template #nextArrow>
            <div class="custom-slick-arrow" style="right: 10px">
                <right-circle-outlined />
            </div>
        </template>
        <div v-for="item in data.dataList" :key="item.id">
            <img :src="item.imageUrl" :style="props.bodyStyle" style="object-fit: cover;" />
        </div>
    </a-carousel>
</template>
<script setup lang="ts">
import { defineProps } from 'vue';
import { LeftCircleOutlined, RightCircleOutlined } from '@ant-design/icons-vue';
import { listApi } from '/@/api/ad';
import { BASE_URL } from "/@/store/constants";

const props = defineProps({
    bodyStyle: {
        type: Object, default: {
            width: '400px',
            height: '320px',
            borderRadius: '10px'
        }
    },
    arrows: Boolean
})
const data = reactive({
    dataList: <any>[],
    queryParam: {
        pageSize: 9999,
        page: 1,
        total: 0,
    },
})
onMounted(() => {
    console.log(props.bodyStyle)
    getDataList()
})
const getDataList = () => {
    listApi(data.queryParam).then((res) => {
        data.dataList = res.data;
        data.queryParam.total = res.total;
        data.dataList.forEach((item: any, index: any) => {
            item.index = index + 1;
            if (item.image) {
                item.imageUrl = BASE_URL + '/api/staticfiles/image/' + item.image
            }
        });
    }).catch((err) => {
        console.log(err);
    });
}
</script>
<style scoped>
/* For demo */
.ant-carousel :deep(.slick-slide) {
    /* text-align: center; */
    /* height: 160px; */
    /* line-height: 160px; */
    /* background: #364d79; */
    overflow: hidden;
}

.ant-carousel :deep(.slick-arrow.custom-slick-arrow) {
    width: 25px;
    height: 25px;
    font-size: 25px;
    color: #fff;
    background-color: rgba(31, 45, 61, 0.11);
    opacity: 0.3;
    z-index: 1;
}

.ant-carousel :deep(.custom-slick-arrow:before) {
    display: none;
}

.ant-carousel :deep(.custom-slick-arrow:hover) {
    opacity: 0.5;
}

.ant-carousel :deep(.slick-slide h3) {
    color: #fff;
}
</style>